/*
 * @Author: H_x
 * @Date: 2024-09-13 10:38:29
 * @LastEditTime: 2024-09-14 18:44:52
 * @LastEditors: H_x
 * @Description: 
 * @FilePath: /browser_captcha_identify/src/entry/background.js
 */
console.log('hello world background todo something~')
import { setStore, getStore } from '@/utils/store'
// const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
// chrome.scripting.executeScript({
//     target: { tabId: tab.id },
//     function: async (key) => {
//         console.log('vvvvvvvvvvvvv');
//         return await new Promise((resolve, reject) => {
//             console.log('vvvvvvvvvvvvv');
            
//             // console.log(getStore({ name: 'confList', }), getStore({ name: 'curForm', }), getStore({ name: 'addShow', }), 'asdasdas');
//         });
//     }
// }).then(res => {
//     console.log(res, 'dfgdfgdfgdfgdfg')
// })

chrome.tabs.query({
    active: true,
    currentWindow: true
}, (tabs) => {
    let message = {
        info: '来自popup的情书💌'
    }
    var messageToContentScript = {
        greeting: "Hello from the background script to a specific tab!"
      };
    chrome.runtime.sendMessage(messageToContentScript);
    chrome.tabs.sendMessage(tabs[0].id, message, res => {
        console.log('popup=>content')
        console.log(res)
    })
})

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
    if (message === 'setPopupShow') {
        if (message.parameter.status) {
            chrome.action.openPopup();
        } else {
            chrome.action.closePopup();
        }
    }
});